﻿using System;
using RestSharp;

namespace ATSSDK;

/// <summary>
/// ATS SDK的配置选项。
/// </summary>
public sealed class ATSOptions
{
    /// <summary>
    /// 客户端ID。由ATS平台分配。
    /// </summary>
    public string ClientId { get; set; }

    /// <summary>
    /// 客户端密码。由ATS平台分配。
    /// </summary>
    public string ClientPassword { get; set; }

    /// <summary>
    /// ATS平台的基础地址。
    /// </summary>
    public string BaseUrl { get; set; }

    /// <summary>
    /// 请求超时时间（秒）。默认为30秒。
    /// </summary>
    public int Timeout { get; set; } = 30;

    public Action<RestClientOptions>? RestClientOptionBuilder { get; set; }

    public void Validate()
    {
        if (string.IsNullOrWhiteSpace(ClientId))
        {
            throw new InvalidOperationException("ClientId is required.");
        }

        if (string.IsNullOrWhiteSpace(ClientPassword))
        {
            throw new InvalidOperationException("ClientPassword is required.");
        }

        if (string.IsNullOrWhiteSpace(BaseUrl))
        {
            throw new InvalidOperationException("BaseUrl is required.");
        }

        if (!Uri.TryCreate(BaseUrl, UriKind.Absolute, out _))
        {
            throw new InvalidOperationException("BaseUrl is not a valid URL.");
        }
    }
}
